package kyssion.leetcode.num101_150;

import kyssion.leetcode.util.ShowUtil;

import java.util.ArrayList;
import java.util.List;

public class code119_杨辉三角形2 {

    public static void main(String[] args) {
        List<Integer> list = new code119_杨辉三角形2().getRow(4);
        ShowUtil.showList(list,false);
    }

    public List<Integer> getRow(int rowIndex) {
        rowIndex++;
        List<Integer> list = new ArrayList<>();
        int[] item = new int[rowIndex];
        for (int a = 1; a <= rowIndex; a++) {
            for (int b = a - 1; b >= 0; b--) {
                if(b==0||b==a-1){
                    item[b] = 1;
                }else{
                    item[b] = item[b]+item[b-1];
                }
            }
        }
        for (int a=0;a<rowIndex;a++){
            list.add(item[a]);
        }
        return list;
    }
}
